Private Sub mnuEditSectionFormat_Click()
Dim result%, jobnum%, mainjob%, sectionN%, sectionCode%, formulaName%
Dim TempText$
If Not CRYSTAL_PRO Then
MsgBox "Options are a Crystal Pro only feature.", vbOKOnly + vbCritical, "Crystal Pro Only"
Exit Sub
End If
result% = PEOpenEngine()
If result% = 0 Then
MsgBox "Could not start the report engine. Execution must halt.", vbOKOnly + vbCritical, "Serious Error"
End
End If
jobnum% = PEOpenPrintJob(lblReportName.Caption) ' Name from label on sample form
ErrorTrap "OpenPrintJob in EditSectionFormat", jobnum%
' Subreport check - if a subreport is currently selected on the main form, jobnum% becomes the subreport
If lblSubreportName.Visible Then
mainjob% = jobnum%
jobnum% = PEOpenSubreport(mainjob%, lblSubreportName.Caption)
ErrorTrap "OpenSubReport in EditSectionFormat", mainjob%
End If
' Load the Sections form for displaying the selection of sections available
Load Sections
CenterForm Sample, Sections
' Start a loop for editing different section format formulae - exit by pressing ok on the sections form
Do While True
Sections.Caption = "Select Section"
Sections!lstSections.Clear
' Fill section list box with appropriate sections for report
result% = PEGetNSections(jobnum%)
ErrorTrap "GetNSections in EditSectionFormat", jobnum%
For sectionN% = 0 To result% - 1
sectionCode% = PEGetSectionCode(jobnum%, sectionN%)
ErrorTrap "GetSectionCode in EditSectionFormat", jobnum%
Select Case sectionCode%
Case Is >= 8000
TempText$ = "Report Footer"
Case Is >= 7000
TempText$ = "Page Footer"
Case Is >= 5000
TempText$ = "Group Footer"
Case Is >= 4000
TempText$ = "Detail"
Case Is >= 3000
TempText$ = "Group Header"
Case Is >= 2000
TempText$ = "Page Header"
Case Is >= 1000
TempText$ = "Report Header"
Case Else
TempText$ = "Unknown Section"
End Select
Sections!lstSections.AddItem TempText$
Sections!lstSections.ItemData(Sections!lstSections.NewIndex) = sectionCode%
Next sectionN%
' Show Section selector form 1 ' Modally
Sections.Show 1 ' Modal
' Find which button was pressed to hide the Sections form
Select Case Sections.Tag
Case "Ok"
Exit Do
Case "Edit"
' Get the section code from the Section form
sectionCode% = Sections!lstSections.ItemData(Sections!lstSections.ListIndex)
' Reload the Sections form with the formula name constants
Sections.Caption = "Select Section Format Formula"
Sections!lstSections.Clear
Sections!lstSections.AddItem "Section Visibility"
Sections!lstSections.ItemData(Sections!lstSections.NewIndex) = SECTION_VISIBILITY
Sections!lstSections.AddItem "New Page Before"
Sections!lstSections.ItemData(Sections!lstSections.NewIndex) = NEW_PAGE_BEFORE
Sections!lstSections.AddItem "Keep Section Together"
Sections!lstSections.ItemData(Sections!lstSections.NewIndex) = KEEP_SECTION_TOGETHER
Sections!lstSections.AddItem "Suppress Blank Section"
Sections!lstSections.ItemData(Sections!lstSections.NewIndex) = SUPPRESS_BLANK_SECTION
Sections!lstSections.AddItem "Reset Page Num After"
Sections!lstSections.ItemData(Sections!lstSections.NewIndex) = RESET_PAGE_N_AFTER
Sections!lstSections.AddItem "Print at Bottom of Page"
Sections!lstSections.ItemData(Sections!lstSections.NewIndex) = PRINT_AT_BOTTOM_OF_PAGE
Sections!lstSections.AddItem "Underlay Section"
Sections!lstSections.ItemData(Sections!lstSections.NewIndex) = UNDERLAY_SECTION
Sections!lstSections.AddItem "Section Back Colour"
Sections!lstSections.ItemData(Sections!lstSections.NewIndex) = SECTION_BACK_COLOUR
' Set up infinite loop to allow for multiple format formula edits
Do While True
' Display Section form (now showing format formulas)
Sections.Show 1 ' Modal
Select Case Sections.Tag
Case "Ok"
Exit Do
Case "Edit"
' Get formula name code from Sections list box
formulaName% = Sections!lstSections.ItemData(Sections!lstSections.ListIndex)
' Get new section format formula
TempText$ = InputBox$("Enter new section format formula:", "New Formula", "")
If TempText$ = "" Then
MsgBox "Cancel pressed or no formula entered. No changes will be made to this format formula.", vbOKOnly + vbCritical, "Cancel Pressed"
Else
result% = PESetSectionFormatFormula(jobnum%, sectionCode%, formulaName%, TempText$)
ErrorTrap "SetSectionFormatFormula in EditSectionFormat", jobnum%
End If
End Select
Loop
End Select
Loop
Unload Sections
' Offer opportunity to see what you did to the report
If MsgBox("Do you want to preview the report?", vbYesNo + vbQuestion, "Preview Report?") = vbYes Then
' Simplified version of the custom-l ink preview routine (no custom buttons)
result% = PEOutputToWindow(jobnum%, "Lines/Section Demonstration Preview" & Chr$(0), CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0)
ErrorTrap "OutputtoWindow in EditSectionFormat", jobnum%
result% = PEStartPrintJob(jobnum%, True)
ErrorTrap "StartPrintJob in EditSectionFormat", jobnum%
result% = 1
Do While result% <> 0
DoEvents
DoEvents
result% = PEGetWindowHandle(jobnum%)
Loop
End If
' Close print job and engine
' Subreport check - if a subreport is currently open, call PreviewReport to offer a chance to
' preview the main report, then close the subreport and main report
If lblSubreportName.Visible Then
PreviewReport mainjob%
result% = PECloseSubreport(jobnum%)
ErrorTrap "CloseSubReport in EditSectionFormat", mainjob%
PEClosePrintJob mainjob%
Else
PEClosePrintJob jobnum%
End If
PECloseEngine
MsgBox "Section Format Formula Complete!", vbOKOnly, "Operation Succeeded"
End Sub
Seagate Software IMG Holdings, Inc. http://www.seagatesoftware.com Support services: http://support.seagatesoftware.com |